#coding=utf-8
import utils

def get_soup(code):
    url = 'http://money.finance.sina.com.cn/corp/go.php/vFD_FinanceSummary/stockid/%s.phtml'%code
    return utils.get_soup(url)

def get_data_from_table(table):
    data = [] 
    t = unicode('截止日期', 'u8' )
    jds = [i.parent.parent.parent for i in table.findAll(text=t)]
    
    for j in jds:
        d = [] 
        for i in range(2):
            d.append(j.contents[3].strong.string)
            j = j.nextSibling.nextSibling
            
        for i in range(11):
            a = j.contents[3].a
            if not a:
                a = j.contents[3]
            d.append(a.string)
            j = j.nextSibling.nextSibling
        data.append(d)
    
    return data
            
def get_data(soup):
    t = unicode('项目：财务摘要', 'u8')
    txt = soup.find(text= lambda(x): x.find(t)!=-1)
    table = txt.parent.parent.parent.parent
    